package com.huadao.cart_ccs.main.login;

import android.os.Bundle;

import com.daolion.base.anotation.BsActivityAnnotation;
import com.huadao.cart_ccs.R;
import com.huadao.cart_ccs.base.BaseActivity;
import com.huadao.cart_ccs.control.ObservableSchedule;
import com.huadao.cart_ccs.main.SerialPortSettingActivity;
import com.huadao.cart_ccs.utils.SerialPortSettingUtils;


@BsActivityAnnotation(layoutId = R.layout.activity_splash)
public class SplashActivity extends BaseActivity {

    private static long SPLASH_LOADING_TIME = 1 * 1800;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ObservableSchedule.downTimeSchedule(SPLASH_LOADING_TIME, o -> switchToNextActivity());
    }

    private void switchToNextActivity() {
        if (SerialPortSettingUtils.isSettingValid(getContext(), false)) {
            launch(getApplicationContext(), LoginActivity.class);
        } else {
            launch(getContext(), SerialPortSettingActivity.class);
        }
        finish();
    }
}
